package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetMealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
@Slf4j
@Api(tags = "套餐管理")
public class SetMealController {
    @Autowired
    private SetMealService setMealService;

    @GetMapping("page")
    @ApiOperation("分页查询套餐信息")
    public Result findByPage(SetmealPageQueryDTO setmealPageQueryDTO) {
        PageResult page  = setMealService.findByPage(setmealPageQueryDTO);
        return Result.success(page);
    }
    @PostMapping("/status/{status}")
    @ApiOperation("修改套餐状态")
    public Result changeStatus(@PathVariable("status") Integer status, Long id) {
      setMealService.changeStatus(status, id);
        return Result.success();
    }
    @DeleteMapping
    @ApiOperation("删除套餐信息")
    public Result delete( @RequestParam List<Long> ids) {
        setMealService.delete(ids);
        return Result.success();
    }
    @GetMapping("/{id}")
    @ApiOperation("通过id查询套餐信息")
    public Result findById(@PathVariable("id") Long id) {
        SetmealVO setmealVO = setMealService.findById(id);
        return Result.success(setmealVO);
    }
    @PutMapping
    @ApiOperation("修改套餐信息")
    public Result update(@RequestBody SetmealDTO setmeal) {
        setMealService.update(setmeal);
        return Result.success();
    }
    @PostMapping
    @ApiOperation("添加套餐信息")
    public Result add(@RequestBody SetmealDTO setmeal) {
        setMealService.add(setmeal);
        return Result.success();
    }


}
